<template>
	<view>
		<view class="wrap">
			<u-row gutter="16">
				<u-col span="12" text-align="left">
					<view class="weikaishi2 lanse" v-html="'单号：'+storageNumber"></view>
				</u-col>
			</u-row>
		</view>
		<u-card padding="16" v-for="(item,index) in dataList" :key="index">
			<view class="" slot="head">
				<view class="wrap">
					<u-row>
						<u-col span="6">
							<view class="weikaishi3 lanse">
								<span>{{item.positionNumber}}库位</span>
							</view>
						</u-col>
					</u-row>
				</view>
			</view>
			<view class="" slot="body">
				<view class="wrap" v-for="(item1,index2) in item.list" :key="index2">
					<u-row>
						<u-col span="12" text-align="right">
							<view class="weikaishi3">
								<u-button type="primary" size="medium" @click="scanChecking(item1.goodsNumber)">扫码比对编号</u-button> 
							</view>
						</u-col>
						<u-col span="12" text-align="left">
							<view class="weikaishi3">
								<span>{{item1.goodsNumber}},{{item1.goodsname}},{{item1.goodsNo}}</span>
							</view>
						</u-col>
					</u-row>
					<u-row>
						<u-col span="12" text-align="left">
							<view class="weikaishi4">
								<span>批次：{{item1.singleBatchnumber}}</span>
							</view>
						</u-col>
						<u-col span="12" text-align="left">
							<view class="weikaishi6">
								<span>包装：{{item1.singlePacking}}</span>
							</view>
						</u-col>
						<u-col span="12" text-align="left">
							<view class="weikaishi6">
								<span>规格：{{item1.goodsSpecs}}</span>
							</view>
						</u-col>
					</u-row>
					<u-row>
						<u-col span="6" text-align="left">
							<view class="weikaishi4">
								<span><u-icon name="clock" size="29" labelSize="14px" labelColor="#000000" label="应入" color="#000000"></u-icon>：{{item1.putNum}}*{{item1.trayNum}}托</span>
							</view>
						</u-col>
						<u-col span="6" text-align="left">
							<view class="yiwancheng weikaishi4" v-if="item1.putNum == item1.realNum">
								<span><u-icon name="checkmark-circle" size="29" labelSize="14px" labelColor="#00c300" label="实入" color="#00c300"></u-icon>：{{item1.realNum}}</span>
							</view>
							<view class="yizuofei weikaishi4" v-else>
								<span><u-icon name="checkmark-circle" size="29" labelSize="14px" labelColor="#e84d74" label="实入" color="#e84d74"></u-icon>：{{item1.realNum}}</span>
							</view>
						</u-col>
						<u-col span="12"  v-if="item1.xianggui">
							<view class="weikaishi3">
								<span><u-icon name="clock" size="29" labelSize="14px" labelColor="#000000" label="换算" color="#000000"></u-icon>：{{parseInt(item1.putNum/item1.xianggui)}}箱{{item1.putNum-parseInt(item1.putNum/item1.xianggui)*item1.xianggui}}盒</span>
							</view>
						</u-col>
					</u-row>
					<u-row >
						<u-col span="2" text-align="center">
							<view class="u-line-1 u-m-t-10 weikaishi">
								<span>托号</span>
							</view>
						</u-col>
						<u-col span="2" text-align="center">
							<view class="u-line-1 u-m-t-10 weikaishi">
								<span>应入</span>
							</view>
						</u-col>
						<u-col span="2" text-align="center">
							<view class="u-line-1 u-m-t-10 weikaishi">
								<span>实入</span>
							</view>
						</u-col>
						<u-col span="2" text-align="center">
							<view class="u-m-t-10 weikaishi">
								<span>库位</span>
							</view>
						</u-col>
						<u-col span="2" text-align="center">
							<view class="u-line-1 u-m-t-10 weikaishi">
								<span>状态</span>
							</view>
						</u-col>
						<u-col span="2" text-align="center">
							<view class="u-line-1 u-m-t-10 weikaishi">
								<span>操作</span>
							</view>
						</u-col>
					</u-row>
					<u-row v-for="(item2,index3) in item1.list" :key="index3">
						<u-col span="2" text-align="center">
							<view class="u-line-1 u-m-t-10 weikaishi6">
								<span>{{item2.trayNumber}}</span>
							</view>
						</u-col>
						<u-col span="2" text-align="center">
							<view class="u-line-1 u-m-t-10 weikaishi">
								<span>{{item2.putNum}}</span>
							</view>
						</u-col>
						<u-col span="2" text-align="center" v-if="item2.putNum == item2.realNum">
							<view class="u-line-1 u-m-t-10 weikaishi">
								<span v-if="item2.realNum">{{item2.realNum}}</span>
							</view>
						</u-col>
						<u-col span="2" text-align="center" v-else>
							<view class="u-line-1 u-m-t-10 yizuofei weikaishi">
								<span v-if="item2.realNum">{{item2.realNum}}</span>
							</view>
						</u-col>
						<u-col span="2" text-align="center">
							<view class="u-m-t-10 weikaishi huanhang">
								<span>{{item2.positionNumber}}</span>
							</view>
						</u-col>
						<u-col span="2" text-align="center">
							<view class="u-line-1 u-m-t-10" v-if="item2.singleState == '未入'">
								<span>{{item2.singleState}}</span>
							</view>
							<view class="u-line-1 u-m-t-10 yiwancheng" v-else>
								<span>{{item2.singleState}}</span>
							</view>
						</u-col>
						<u-col span="1" text-align="center" @click="findyichang(item2)">
							<view class="u-line-1 u-m-t-10">
								<u-icon name="tags" color="#2979ff" size="36"></u-icon>
							</view>
						</u-col>
						<u-col span="1" text-align="center" @click="editnum(item2)">
							<view class="u-line-1 u-m-t-10">
								<u-icon name="edit-pen" color="#2979ff" size="36"></u-icon>
							</view>
						</u-col>
					</u-row>
					<u-row>
						<u-col span="12" text-align="right" >
							<view class="u-m-t-30 u-line-1">
							</view>
						</u-col>
					</u-row>
				</view>
			</view>
		</u-card>
		<u-popup v-model="show" mode="center" closeable width="500rpx" height="300rpx" border-radius="10">
			<view class="u-text-center u-m-t-20">异常</view>
			<view class=" u-m-20">
				<u-input v-model="realNum" type="digit" border="true" placeholder="请输入实际数量"/>
			</view>
			<view  style="height: 80rpx">
				<view class="close-btn u-m-t-40">
					<u-button size="medium" @click="define()">确定</u-button>
				</view>
			</view>
		</u-popup>
		<u-popup v-model="show2" mode="center" closeable width="560rpx" height="720rpx" border-radius="10">
			<view class="u-text-center u-m-t-20 weikaishi2">异常处理记录</view>
			<u-card padding="16" v-for="(item,index) in yichanglist" :key="index">
				<view class="" slot="head">
					<view class="wrap">
						<u-row>
							<u-col span="12" text-align="left">
								<view class="weikaishi3">
									<span>异常类型：{{item.types}}</span>
								</view>
							</u-col>
						</u-row>
					</view>
				</view>
				<view class="" slot="body">
					<view class="wrap">
						<u-row>
							<u-col span="6">
								<view class="u-line-1 u-m-t-10">
									<span>应入：{{item.num}}</span>
								</view>
							</u-col>
							<u-col span="6" v-if="item.num == item.shirunum">
								<view class="u-line-1 u-m-t-10">
									<span>实入：{{item.shirunum}}</span>
								</view>
							</u-col>
							<u-col span="6" v-else>
								<view class="u-line-1 u-m-t-10 yizuofei">
									<span>实入：{{item.shirunum}}</span>
								</view>
							</u-col>
						</u-row>
						<u-row>
							<u-col span="12">
								<view class=" u-m-t-10">
									<span>异常说明：{{item.notes}}</span>
								</view>
							</u-col>
						</u-row>
						<u-row>
							<u-col span="6">
								<view class=" u-m-t-10">
									<span>处理人：{{item.userName}}</span>
								</view>
							</u-col>
							<u-col span="6">
								<view class=" u-m-t-10">
									<span>时间：{{item.chuliTime}}</span>
								</view>
							</u-col>
						</u-row>
					</view>
				</view>
			</u-card>
		</u-popup>
		<view>
			<u-toast ref="uToast" />
		</view>
	</view>
</template>
<script>
	import config from '../../config.js'
	export default {
		data() {
			return {
				dataList: [],
				storageNumber:'',
				goodsId:'',
				
				tid:'',
				realNum:'',
				show:false,
				show2:false,
				
				yichanglist: [],
			}
		},
		onLoad(open) {
			//#ifdef H5 || APP-PLUS
			this.flex = 'u-flex'
			//#endif
			
			this.storageNumber = open.storageNumber
			this.goodsId = open.goodsId
			this.refresh()
		},
		onPullDownRefresh() {
			this.refresh()
			uni.stopPullDownRefresh()
		},
		methods: {
			scanChecking(goodsNumber){
				let that = this
				uni.scanCode({
					success: function (res) {
						console.log('条码类型：' + res.scanType);
						console.log('条码内容：' + res.result);
						if(res.result == goodsNumber){
							uni.showToast({
								title: '比对一致',
								duration: 2000
							});
							//验证商品编号一致  播报语音
							const innerAudioContext = uni.createInnerAudioContext();
							innerAudioContext.autoplay = true;
							innerAudioContext.src = config.root +'/system/audio_success';
							innerAudioContext.onPlay(() => {
							  console.log('开始播放');
							});
							innerAudioContext.onError((res) => {
							  console.log(res.errMsg);
							  console.log(res.errCode);
							});
						} else {
							uni.showToast({
								title: '比对不一致！',
								duration: 2000,
								icon:'none',
							});
							//验证商品编号不一致  播报语音
							const innerAudioContext = uni.createInnerAudioContext();
							innerAudioContext.autoplay = true;
							innerAudioContext.src = config.root +'/system/audio_error';
							innerAudioContext.onPlay(() => {
							  console.log('开始播放');
							});
							innerAudioContext.onError((res) => {
							  console.log(res.errMsg);
							  console.log(res.errCode);
							});
						}
					}
				});
			},
			findyichang(item){
				this.$http.post('/rest/storagePut/findyichang',{
				},{
					params:{
						detailedId: item.id,
					},
					header: {
						'Authorization' :uni.getStorageSync('token'),
					}
				}).then(res => {
					this.show2 = true
					this.yichanglist = res.data.data
				})
			},
			define(){
				if(typeof this.realNum == 'undefined' || this.realNum == null || this.realNum == ""){
					uni.showToast({
						title: "请输入实入数量",
						icon: 'none'
					})
					return
				}
				uni.showLoading({
					title: '正在提交'
				})
				this.$http.post('/rest/storagePut/editnum',{
				},{
					params:{
						id: this.tid,
						realNum: this.realNum,
					},
					header: {
						'Authorization' :uni.getStorageSync('token'),
					}
				}).then(res => {
					uni.hideLoading()
					if(res.data.code == 200) {
						this.$refs.uToast.show({
							title: '异常处理成功，已退回至入库',
							type: 'success'
						})
						setTimeout(() => {
							this.refresh()
						}, 600)
						this.show = false
					} else {
						this.$refs.uToast.show({
							title: res.data.message,
							type: 'error'
						})
						setTimeout(() => {
							this.refresh()
						}, 1000)
					}
				})
			},
			editnum(item){
				this.tid = item.id
				this.show = true
			},
			refresh(){
				uni.showLoading({
					title: '加载中...'
				})
				this.$http.post('/rest/storagePut/confirmplist',{
				},{
					params: {
						storageNumber: this.storageNumber,
						goodsId:this.goodsId
					},
					header: {
						'Authorization' :uni.getStorageSync('token'),
					}
				}).then(res => {
					this.dataList = res.data.data
					for(let item1 of res.data.data) {
						if(this.storageNumber == ''){
							this.storageNumber = item1.storageNumber
							break
						}
					}
					uni.hideLoading()
				})
				
			},
		},
	}
</script>
<style lang="scss">
	.weikaishi2{
		margin: 25rpx 20rpx 0rpx 20rpx;
	}
	.huanhang{
		word-break:break-all;
	}
</style>
